package com.ruoyi.web.controller.vpn;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.vpn.domain.VpnPlan;
import com.ruoyi.vpn.service.IVpnPlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * planController
 * 
 * @author Edwin
 * @date 2024-01-08
 */
@RestController
@RequestMapping("/vpn/plan")
public class VpnPlanController extends BaseController
{
    @Autowired
    private IVpnPlanService vpnPlanService;

    /**
     * 查询plan列表
     */
    @PreAuthorize("@ss.hasPermi('vpn:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(VpnPlan vpnPlan)
    {
        startPage();
        List<VpnPlan> list = vpnPlanService.selectVpnPlanList(vpnPlan);
        return getDataTable(list);
    }

    /**
     * 导出plan列表
     */
    @PreAuthorize("@ss.hasPermi('vpn:plan:export')")
    @Log(title = "plan", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VpnPlan vpnPlan)
    {
        List<VpnPlan> list = vpnPlanService.selectVpnPlanList(vpnPlan);
        ExcelUtil<VpnPlan> util = new ExcelUtil<VpnPlan>(VpnPlan.class);
        util.exportExcel(response, list, "plan数据");
    }

    /**
     * 获取plan详细信息
     */
    @PreAuthorize("@ss.hasPermi('vpn:plan:query')")
    @GetMapping(value = "/{planId}")
    public AjaxResult getInfo(@PathVariable("planId") Long planId)
    {
        return success(vpnPlanService.selectVpnPlanByPlanId(planId));
    }

    /**
     * 新增plan
     */
    @PreAuthorize("@ss.hasPermi('vpn:plan:add')")
    @Log(title = "plan", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VpnPlan vpnPlan)
    {
        return toAjax(vpnPlanService.insertVpnPlan(vpnPlan));
    }

    /**
     * 修改plan
     */
    @PreAuthorize("@ss.hasPermi('vpn:plan:edit')")
    @Log(title = "plan", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VpnPlan vpnPlan)
    {
        return toAjax(vpnPlanService.updateVpnPlan(vpnPlan));
    }

    /**
     * 删除plan
     */
    @PreAuthorize("@ss.hasPermi('vpn:plan:remove')")
    @Log(title = "plan", businessType = BusinessType.DELETE)
	@DeleteMapping("/{planIds}")
    public AjaxResult remove(@PathVariable Long[] planIds)
    {
        return toAjax(vpnPlanService.deleteVpnPlanByPlanIds(planIds));
    }
}
